package com.lxb.myforum.pojo

import java.util.Date

import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.EnumType
import javax.persistence.Enumerated
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.Table
import javax.persistence.Temporal
import javax.persistence.TemporalType

/**
 * 收藏
 *
 * @author lxb
 */

@Entity
@Table(name = "t_star")
data class Star (
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long? = null,

    // 收藏用户
    @ManyToOne(targetEntity = User::class)
    @JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false)
    var user: User? = null,

    // 被收藏者类型
    @Enumerated(EnumType.STRING)
    @Column(name = "target_type")
    var type: StarType? = null,

    // 被收藏者对应id
    @Column(name = "target_id")
    var targetId: Long? = null,

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "create_time")
    var createTime: Date? = null
)


enum class StarType {
    ARTICLE, POST, QUESTION, ANSWER
}
